package com.hashnode.mybatisreverse.service;

import com.hashnode.mybatisreverse.mapper.StudentMapper;
import com.hashnode.mybatisreverse.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class StudentService {
    @Autowired
    private StudentMapper studentMapper;

    public Student queryStudentById(Integer id){
        Student student = studentMapper.selectByPrimaryKey(id);
        return student;
    }

    //完整的业务,有错误就回滚
    @Transactional
    public void updateStudentById(Student student) {
//        修改成功
        studentMapper.updateByPrimaryKeySelective(student);
//        如果student.getAge()为0为异常
        int a = 10/student.getAge();
    }
}
